package com.alibaba.algo;

import com.google.common.eventbus.EventBus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * Created by IntelliJ IDEA.
 * User: glorysongglory
 * Date: 2020/11/17
 * Time: 17:56
 */
@Component
@Slf4j
public class EventH1 {

    @Autowired
    private EventBus eventBus;

    @Autowired
    private EventBus eventBusAlgo;

    @Autowired
    private EventListener eventListener;

    @Autowired
    private EventListener1 eventListener1;

    @PostConstruct
    public void init() {
        eventBus.register(eventListener);
        eventBusAlgo.register(eventListener);
        eventBusAlgo.register(eventListener1);
    }

    @PreDestroy
    public void destroy() {
        eventBus.unregister(eventListener);
        eventBusAlgo.unregister(eventListener);
        eventBusAlgo.unregister(eventListener1);
    }

    public void eventPost(){
        eventBus.post("test");
        eventBusAlgo.post("algo");
        log.info("post event");
    }

}
